Python for Beginners: Learn Python Quickly and Easily: A Python Crash Course by Nick Porter

Python for Beginners: Learn Python Quickly and Easily: A Python Crash Course by Nick Porter

Author:Nick Porter
Language: eng
Format: mobi, epub, azw3, pdf
Publisher: Python Programming Publishing
Published: 2016-01-04T22:00:00+00:00


Exercise #50: Deleting key and associated value using POP

Open Dictionary.py. Run->Run Module. In python shell type:

1.

2.

3.

4.

5.

6.

>>> books.pop (111)

>>>

>>> books

>>> deleteditem = books.pop(2222)

>>> print (deleteditem)

>>> books

>>>

In the above example we have deleted the key-value pair for the key 111. You will see that the pop command prints the value for key 111; in other word the pop command returns the value for key 111 i.e. Black Beauty. In line 3 we print the contents of books dictionary to see the remaining items.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.